using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using System;
using System.Collections;
using yW5Lib;

namespace yWriter6
{
	[StandardModule]
	internal sealed class modWordsPerChar
	{
		public static void ShowWordsPerChar(clsProject cProject)
		{
			//Discarded unreachable code: IL_0161, IL_0178, IL_0183, IL_0193, IL_01fd, IL_01ff, IL_0213, IL_0235
			int num = default(int);
			int num4 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				if (cProject.Wordcount() == 0)
				{
					num2 = 3;
					clsShared.cLang.TransMsgBox("There aren't any words in this project");
				}
				else
				{
					num2 = 5;
					UpdateWordsPerChar(cProject);
					num2 = 6;
					string text = "";
					num2 = 7;
					int num3 = cProject.Wordcount();
					num2 = 8;
					IEnumerator enumerator = cProject.Chars.GetEnumerator();
					while (enumerator.MoveNext())
					{
						clsCharacter clsCharacter = (clsCharacter)enumerator.Current;
						num2 = 9;
						string text2;
						if (clsCharacter.WordCount == 0)
						{
							num2 = 10;
							text2 = "(0.00%)";
						}
						else
						{
							num2 = 12;
							text2 = Strings.Format((double)clsCharacter.WordCount / (double)num3, "(0.00%)");
						}
						num2 = 13;
						text = text + clsCharacter.Title + ": " + Conversions.ToString(clsCharacter.WordCount) + " " + text2 + "\r\n";
						num2 = 14;
					}
					num2 = 15;
					if (enumerator is IDisposable)
					{
						(enumerator as IDisposable).Dispose();
					}
					num2 = 16;
					if (Operators.CompareString(text, "", TextCompare: false) == 0)
					{
						num2 = 17;
						clsShared.cLang.TransMsgBox("No characters");
					}
					else
					{
						num2 = 19;
						clsShared.cLang.TransMsgBox("@1@(Does not include unused scenes or scenes within unused chapters)", MsgBoxStyle.OkOnly, "", text + "\r\n");
					}
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num4 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_0233: Could not find block for branch target IL_01ff*/;
			}
			if (num4 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}

		public static void UpdateWordsPerChar(clsProject cProject)
		{
			//Discarded unreachable code: IL_0139, IL_0150, IL_015b, IL_016b, IL_01cd, IL_01cf, IL_01e3, IL_0205
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				clsShared.cSubs.BusyMouse();
				num2 = 3;
				IEnumerator enumerator = cProject.Chars.GetEnumerator();
				while (enumerator.MoveNext())
				{
					clsCharacter clsCharacter = (clsCharacter)enumerator.Current;
					num2 = 4;
					clsCharacter.WordCount = 0;
					num2 = 5;
				}
				num2 = 6;
				if (enumerator is IDisposable)
				{
					(enumerator as IDisposable).Dispose();
				}
				num2 = 7;
				IEnumerator enumerator2 = cProject.Chapters.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					clsChapter clsChapter = (clsChapter)enumerator2.Current;
					num2 = 8;
					if (!clsChapter.Unused & (clsChapter.Type == ChapterTypes.ChapterNormal))
					{
						num2 = 9;
						int sceneCount = clsChapter.SceneCount;
						for (int i = 1; i <= sceneCount; i++)
						{
							num2 = 10;
							clsScene clsScene = cProject.get_SceneByID(clsChapter.get_SceneIDByIndex(i));
							num2 = 11;
							if (!clsScene.Unused)
							{
								num2 = 12;
								clsCharacter clsCharacter = cProject.get_CharByID(clsScene.ViewPointID);
								num2 = 13;
								clsCharacter.WordCount += clsScene.Wordcount;
							}
							num2 = 14;
						}
					}
					num2 = 15;
				}
				num2 = 16;
				if (enumerator2 is IDisposable)
				{
					(enumerator2 as IDisposable).Dispose();
				}
				num2 = 17;
				clsShared.cSubs.NormalMouse();
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_0203: Could not find block for branch target IL_01cf*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
